package com.iwunu.iot.common.util;

import org.apache.commons.lang3.StringUtils;

import com.iwunu.iot.common.adapter.MessageConversionAdapter;

public class MessageAssembleUtil {
	
	private static String index = "680201";
	private static String serviceType ="0001";
	private static String flag="34";
	private static String datalength = "05";
	private static String end="0016";
	
	public static String remoteOpenAssemble(String msg,String deviceId,String first) {
		
		first = StringUtils.leftPad(first, 2, "0");
		String time = MessageConversionAdapter.getTimestamp(msg);
		String currenttime = Long.toHexString(DateUtil.getNowTime());
		StringBuffer openBuf =  new StringBuffer(index);
		openBuf.append(deviceId).append(MessageConversionAdapter.getRandom(msg));
		openBuf.append(serviceType);
		openBuf.append(time).append("0007").append(flag).append(datalength);
		openBuf.append(first).append(currenttime).append(end);
		return openBuf.toString();
	}

}
